<?php
namespace Web\Controller;
use Think\Controller;
use Web\Controller\BaseController;
class AudioController extends BaseController {

    public function _initialize(){
        //如果session存在，传递用户信息
        $midiuser = session('midiuser');
        $this->assign('midiuser',$midiuser);
    }

//=====================================    音频    =================================

    //音频首页
    public function audio_index(){
        $data = array_filter($_GET);
        if (!empty($data['type'])) {
        	$type_arr = explode('_',$data['type']);
	        $data['audio_major_id'] = $type_arr[0];
	        $data['audio_level'] = $type_arr[1];
	        unset($data['type']);
        }
        unset($data['p']);
        $data['audio_display'] = 1;
        $count = M('audio')->where($data)->count();
        $page = getpage($count,10);
        $audio_arr = M('audio')->where($data)->order('audio_level asc')->limit($page->firstRow, $page->listRows)->select();
        $this->assign('audio_arr', $audio_arr);
        $this->assign('page', $page->show());
        $this->display();
    }

    //音频详情
    public function audio_details(){
        $midiuser = session('midiuser');
        if (empty($midiuser)) {
            $this->error('查看音频详情请先登录',U('Index/login'));
        }
        if (empty($_GET['id'])) {
            $this->error('音频不存在');
        }
        $data['audio_id'] = $_GET['id'];
        $data['audio_display'] = 1;
        $audio_arr = M('audio')->where($data)->find();
        $this->assign('audio_arr',$audio_arr);
        $this->assign('audio_file1',$audio_arr['audio_file1']);
        $this->assign('audio_file2',$audio_arr['audio_file2']);
        $this->assign('audio_file3',$audio_arr['audio_file3']);
        $this->assign('audio_major',$audio_arr['audio_major_id']);
        $this->display();
    }


//=====================================    视频    =========================================


	//视频首页
    public function video_index(){
        $data = array_filter($_GET);
        if (!empty($data['type'])) {
            $type_arr = explode('_',$data['type']);
            $data['video_major_id'] = $type_arr[0];
            $data['video_level'] = $type_arr[1];
            unset($data['type']);
        }
        unset($data['p']);
        $data['video_display'] = 1;
        $count = M('video')->where($data)->count();
        $page = getpage($count,6);
        $video_arr = M('video')->where($data)->order('video_level asc')->limit($page->firstRow, $page->listRows)->select();
        $this->assign('video_arr', $video_arr);
        $this->assign('page', $page->show());
        $this->display();
    }
}